//Wdg2DPlot.cpp
/*    widgetpp - A simple C++ wrapper of DISLIN graphic library               */
/*                                                                            */
/*    Copyright (C) 2012  Mirko Cambi (email: mirko.cambi@gmail.com)          */
/*                                                                            */
/*    This program is free software: you can redistribute it and/or modify    */
/*    it under the terms of the GNU General Public License as published by    */
/*    the Free Software Foundation, either version 3 of the License, or       */
/*    (at your option) any later version.                                     */
/*                                                                            */
/*    This program is distributed in the hope that it will be useful,         */
/*    but WITHOUT ANY WARRANTY; without even the implied warranty of          */
/*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           */
/*    GNU General Public License for more details.                            */
/*                                                                            */
/*    You should have received a copy of the GNU General Public License       */
/*    along with this program.  If not, see <http://www.gnu.org/licenses/>.   */

#include "Wdg2DPlot.hpp"
#include "dislin.h"

using namespace wdgpp;

Wdg2DPlot::Wdg2DPlot(): _graf(false), _draw_fun(0), _title(0), _axis(0)
{
}

void Wdg2DPlot::init(int ip, int nxp, int nyp, bool border)
{
   if(ip > 0)
      setxid(ip, "WIDGET");

   metafl("GL");
   if(nxp > 0 && nyp > 0)
      page(nxp, nyp);
   
   disini();
   if(border)
      pagera();
}

void Wdg2DPlot::cartesian_axis(
   float xlo, float xup, float xstart, float xstep, 
   float ylo, float yup, float ystart, float ystep
)
{
   _graf = true;
   graf(xlo, xup, xstart, xstep, ylo, yup, ystart, ystep);
}

void Wdg2DPlot::polar_axis(
   float xup, float xstart, float xstep, float ystart, float ystep
)
{
   _graf = true;
   grafp(xup, xstart, xstep, ystart, ystep);
}

void Wdg2DPlot::set_position(int xpos, int ypos) const
{
   axspos(xpos, ypos);
}

void Wdg2DPlot::set_lenght(int xlen, int ylen) const 
{
   axslen(xlen, ylen);
}

void Wdg2DPlot::set_draw_function(draw_fun_type f)
{
   _draw_fun = f;   
}

void Wdg2DPlot::set_title(WdgTitle *title)
{
   _title = title;
}

void Wdg2DPlot::set_axis(Wdg2DAxis *axis)
{
   _axis = axis;
}

void Wdg2DPlot::erase() const
{
   ::erase();
}

void Wdg2DPlot::close() const
{
   if(_graf)
      endgrf();
   
   disfin();
}

void Wdg2DPlot::draw() const
{
   if(_title)
      _title->draw();

   if(_axis)
      _axis->draw();

   if(_draw_fun)
      _draw_fun();
}

